package org.fioma.ui;

import java.io.IOException;

import org.fioma.tree.bytes.RootBytes;
import org.fioma.tree.suffixTree.bytes.SuffixTreeBytes;

public class Tools {

	public static final RootBytes buildWordTree(String fileFastQName, int k) throws IOException {
		RootBytes root = new RootBytes();
		FastQ fastQ = new FastQ(fileFastQName, k);
		byte[] dnaSeq;

		int i = 0;
		while ((dnaSeq = fastQ.getNextSeq()) != null) {
			i++;
			root.addWord(dnaSeq);
			if (i % 1000000 == 0) {
				System.out.println(i);
			}
		}

		System.out.println(i);
		return root;
	}

	public static final SuffixTreeBytes buildSuffixTree(String fileFastQName, int k) throws IOException {
		SuffixTreeBytes tree = new SuffixTreeBytes(k);
		FastQ fastQ = new FastQ(fileFastQName, k);
		byte[] dnaSeq;

		int i = 0;
		while ((dnaSeq = fastQ.getNextSeq()) != null) {
			i++;
			tree.addSuffixes(dnaSeq);

			if (i % 1000 == 0) {
				System.out.println(i);
			}
		}

		System.out.println(i);
		return tree;
	}

}
